home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-04-06 | 12.4 KB | 374 lines | [TEXT/MPS ] |
- # CompareFiles - Compare two source files and show the differences
- #
- # Version 3.4.2d1
- #
- # Usage:
- # CompareFiles [-TopDown] [-compareOpts options…] [-9 | -LC | -12 | -13 | -Portrait | -15 | -16 | -17 | -TwoPage | -21 | -b x y | -r t,l,b,r] oldFile (newFile | newDir)
- # -9 use 9 inch screen (512 x 342)
- # -LC | -12 use 12 inch screen (512 x 384)
- # -13 use 13 inch screen (640 x 480)
- # -Portrait | -15 use 15 inch screen (640 x 870)
- # -16 use 16 inch screen (832 x 624)
- # -17 use 17 inch screen Multiscan at max scan (1024 x 768)
- # -TwoPage | -21 use 21 inch screen (1152 x 870)
- # -b x y use screen dimensions given in x y
- # -r t,l,b,r use screen rect given by Top,Left,Bottom,Right
- # -TopDown allow editing from top to bottom rather than bottom to top.
- # -compareOpts additional options passed along to the Compare tool
- #
- # The default is to use the dimensions of the main monitor.
- #
- # NOTE:
- # No error checking is done on x y coordinates
- #
- # Returns:
- # Status = 0 - files match
- # Status = 1 - syntax error
- # Status = 2 - files differ (this is the same status as the Compare tool)
- #
- # CompareFiles will compare two files, and if they don't match it will bring them
- # both up on the screen and put them side by side. A menu will be appended to the
- # menu bar to go through the changes. When all the changes have been shown, the
- # file windows will be restored and closed.
- #
- # In addition to the menu the following keys are provided to do the menu operations:
- #
- # Control+UpArrow Moves to the next mismatch
- # Control+DownArrow Moves to the next mismatch (same as Control+UpArrow)
- # Control+RightArrow Copy selection from left file to right file
- # Control+LeftArrow Copy selection from right file to left file
- #
- # If the -TopDown option is not specified the differences are shown from bottom to top
- # so that if any changes are made in the files the line offsets are not messed up. If
- # -TopDown is specified, the changes CAN be made from the top down due to the fact that
- # the files are recompared before moving to the next mismatch. Although this may sound
- # more inefficient than bottom-up comparing, it is in fact faster! This is because the
- # Compare tool is very fast plus it only has to read the files starting at the previous
- # mismatch and quits as soon as the next mismatch is found. This is the more natural
- # way to edit the files. Bottom-up processing is supported (as the default) only for
- # compatibility. It's slower since a helper script must be executed to search a file
- # of Compare output for the previous mismatch.
- #
- # When not using -TopDown, the temporary file {TempFolder}Compare_File is created to hold
- # the Compare output. This file is deleted on exit.
- #
- # Copyright Apple Computer, Inc. 1988 - 1998
- # All rights reserved.
- #
- # Version 3.3 by Peter Potrebic with enhancements by Greg Branche
- # Version 3.4.1 enhancements by Ira L. Ruben
- # Version 3.4.2 enhancements by Greg Branche
- #
- # Helper script and tools referenced by this script:
- #
- # CompareFiles•NextChange - script to show next change (used when not using -Topdown)
- # CompareFiles•Quit - script to clean up when finished
- # Monitors - command to get default main screen dimensions
- #
- # Implementation details -- The -TopDown option assumes the new version of Compare which
- # supports the -selection option for getting and setting selections.
- #
- # The Monitors command is an MPW command that is used by this script to get the dimensions
- # of the main monitor as the default display size.
- #
-
- Set Exit 0
- Set CaseSensitive 0
- Set ErrorMessage "### CompareFiles - Incorrect order, or missing or illegal option"
- Set Usage "# Usage - CompareFiles [-TopDown] [-compareOpts options...] [-9 | -LC | -12 | -13 | -Portrait | -15 | -16 | -17 | -TwoPage | -21 | -b x y | -r t,l,b,r] oldFile (newFile | newDir)"
-
- Set CompareOptions "-g 3 -b -m -t {DefaultCompareFilesOptions}"
- UnSet File1
- UnSet File2
-
- (Evaluate "`Monitors`" =~ /(≈)®1,(≈)®2,(≈)®3,(≈)®4/) >Dev:Null
- Set Top "{®1}"
- Set Left "{®2}"
- Set Bottom "{®3}"
- Set Right "{®4}"
- Evaluate Left = {Left} + 5
- Evaluate Right = {Right} - 4
- Evaluate Bottom = {Bottom} - 142
- Set CompareFilesTileRectangle "{Top}, {Left}, {Bottom}, {Right}"
- Evaluate Bottom = {Bottom} + 1
- Evaluate Right = {Right} - 9
-
- Set TopDown 0
-
- loop # process the options...
- Break if {#} == 0
- If !{#} # Done?
- If !"{File2}"
- Alert "Must specify two (and only two) files.∂n∂n{Usage}"
- Exit 1
- End
- Break
- End
-
- If "{1}" !~ /-≈/ # Filename?
- If !"{File1}"
- Set File1 "{1}"
- Shift
- Continue
- end
- If !"{File2}"
- Set File2 "{1}"
- Shift
- Continue
- end
- Alert "Must specify two (and only two) files.∂n∂n{Usage}"
- Exit 1
- End
- If "{1}" =~ /-td/ || "{1}" =~ /-topdown/ # -topdown
- Set TopDown 1
- Shift 1
- Continue
- End
- If "{1}" =~ /-TwoPage/ || "{1}" =~ /-21/ # -TwoPage, -21
- Set CompareFilesTileRectangle "0, 5, 727, 1148"
- Set Bottom 728
- Set Right 1139
- Shift 1
- Continue
- End
- If "{1}" =~ /-17/ # -17
- Set CompareFilesTileRectangle "0, 5, 625, 1020"
- Set Bottom 626
- Set Right 1011
- Shift 1
- Continue
- End
- If "{1}" =~ /-Portrait/ || "{1}" =~ /-15/ # -Portrait, -15
- Set CompareFilesTileRectangle "0, 5, 754, 635"
- Set Bottom 755
- Set Right 626
- Shift 1
- Continue
- End
- If "{1}" == "-16" # -16 (Apple 16" screen)
- Set CompareFilesTileRectangle "0, 5, 482, 828"
- Set Bottom 483
- Set Right 819
- Shift 1
- Continue
- End
- If "{1}" =~ /-13/ # -13 (MacII screen)
- Set CompareFilesTileRectangle "0, 5, 344, 635"
- Set Bottom 345
- Set Right 626
- Shift 1
- Continue
- End
- If "{1}" =~ /-LC/ || "{1}" =~ /-12/ # -LC (LC 12" RGB screen)
- Set CompareFilesTileRectangle "0, 3, 240, 510"
- Set Bottom 241
- Set Right 500
- Shift 1
- Continue
- End
- If "{1}" == "-9" # -9 (Mac+ and MacSE screen)
- Set CompareFilesTileRectangle "0, 3, 198, 510"
- Set Bottom 199
- Set Right 500
- Shift 1
- Continue
- End
- If "{1}" == "-b" || "{1}" == "-B" # -b x y
- Evaluate Right = {2} - 5
- Evaluate Bottom = {3} - 140
- Set CompareFilesTileRectangle "0,5,{Bottom},{Right}"
- Evaluate Bottom = {Bottom} + 1
- Evaluate Right = {Right} - 9
- Shift 3
- Continue
- End
- If "{1}" == "-r" || "{1}" == "-R" # -r t,l,b,r
- (Evaluate "{2}" =~ /(≈)®1,(≈)®2,(≈)®3,(≈)®4/) >Dev:Null
- Set Top "{®1}"
- Set Left "{®2}"
- Set Bottom "{®3}"
- Set Right "{®4}"
- Evaluate Bottom = {Bottom} - 120
- Set CompareFilesTileRectangle "{Top}, {Left}, {Bottom}, {Right}"
- Evaluate Bottom = {Bottom} + 1
- Evaluate Left = {Left} + 2
- Evaluate Right = {Right} - {Left} - 2
- Shift 2
- Continue
- end
- If "{1}" == "-compareOpts"
- Set CompareOptions "{CompareOptions} {2}"
- Shift 2
- Continue
- end
- Alert "Invalid option ("{1}")∂n∂n{Usage}"
- exit 1
- end
-
- if !"{File1}" || !"{File2}"
- Alert "Must specify two (and only two) files.∂n∂n{Usage}"
- Exit 1
- end
-
- # add the ability to specify a filename and a directory
- # the same named file from the two directories is then compared
-
- set File1Directory "`Exists -d "{File1}"`"
- if ("{File1Directory}" != "")
- set File1 "{File1Directory}{File2}"
- end
- set File2Directory "`exists -d "{File2}"`"
- if ("{File2Directory}" != "")
- set File2 "{File2Directory}{File1}"
- end
-
- if ("{File1Directory}" != "") && ("{File2Directory}" != "")
- Alert "Must specify at least one file and one directory file.∂n∂n{Usage}"
- exit 1
- end
-
-
- if {TopDown}
- Evaluate Bottom = {Bottom} + 119
- Evaluate Right = {Right} + 9
- Set CompareFilesTileRectangle "{Top}, {Left}, {Bottom}, {Right}"
- Evaluate Bottom = {Bottom} + 1
- Evaluate Right = {Right} - 9
- end
-
- Set ActiveAtStart "{Active}"
- Set TargetAtStart "{Target}"
-
- Set CompareStatus 0
- Compare {CompareOptions} "{{File1}}" "{{File2}}" > "{TempFolder}"Compare_File || Set CompareStatus {Status}
-
- if {CompareStatus} == 0
- Echo "### files are equal (ignoring blanks): {File1} - {File2}"
- Delete -i "{TempFolder}Compare_File" ≥ dev:null
- else if {CompareStatus} == 2 || {CompareStatus} == 4 # files don’t match - set everything up
- if !{TopDown}
- StreamEdit "{{TempFolder}}"Compare_File -o "{{TempFolder}}"Compare_File ∂
- -e '/•[ ∂t]*File (≈)®1; Line (≈)®2; File (≈)®3; Line (≈)®4/ Change " Find "®2" "®1"; Find "®4" "®3'
- Set NothingMatches 1
- Search -s /•∂*∂*∂* Nothing seems to match ∂*∂*∂*/ "{{TempFolder}}"Compare_File ∑∑dev:null || Set NothingMatches 0
- else if {CompareStatus} == 4
- Set NothingMatches 1
- else
- Set NothingMatches 0
- end
- If {NothingMatches}
- Beep
- Confirm "Nothing matches! Continue the file comparison?"
- If {Status} == 4
- if !{TopDown}
- Delete -i "{{TempFolder}}"Compare_File
- end
- Exit 3
- End
- End
-
- Set File1 "`Files -f -q "{File1}"`" # get full pathnames
- Set File2 "`Files -f -q "{File2}"`"
-
- Unset Close1 Close2 # remember if either file is already open
- Set openWindows " ``Windows -q`` "
- If "{openWindows}" !~ /≈ [∂']*"{File1}"[∂']* ≈/; Open "{File1}"; Set Close1 1; End
- If "{openWindows}" !~ /≈ [∂']*"{File2}"[∂']* ≈/; Open "{File2}"; Set Close2 1; End
-
- # Save current selection so we can restore it when we're done
- Mark -y § __cfSelectionOnEntry__ "{{File1}}" ≥dev:null
- Mark -y § __cfSelectionOnEntry__ "{{File2}}" ≥dev:null
-
- set W1location "`MoveWindow "{{File1}}";echo ∂;;SizeWindow "{{File1}}"`"
- set W2location "`MoveWindow "{{File2}}";echo ∂;;SizeWindow "{{File2}}"`"
-
- If "``SetKey Control-RightArrow ≥dev:null``" == ""
- Set ResetRightArrow "UnsetKey Control-RightArrow"
- Else
- Set ResetRightArrow "``SetKey Control-RightArrow ≥dev:null``"
- End; ∂
- If "``SetKey Control-LeftArrow ≥dev:null``" == ""
- Set ResetLeftArrow "UnsetKey Control-LeftArrow"
- Else
- Set ResetLeftArrow "``SetKey Control-LeftArrow ≥dev:null``"
- End; ∂
- If "``SetKey Control-DownArrow ≥dev:null``" == ""
- Set ResetDownArrow "UnsetKey Control-DownArrow"
- Else
- Set ResetDownArrow "``SetKey Control-DownArrow ≥dev:null``"
- End; ∂
- If "``SetKey Control-UpArrow ≥dev:null``" == ""
- Set ResetUpArrow "UnsetKey Control-UpArrow"
- Else
- Set ResetUpArrow "``SetKey Control-UpArrow ≥dev:null``"
- End; ∂
-
- # set up clean-up script
- Begin
- Echo Begin
- Echo ∂tSet Exit 0
- Echo ∂tDeleteMenu Compare
- Echo ∂t"{ResetRightArrow}"
- Echo ∂t"{ResetLeftArrow}"
- Echo ∂t"{ResetDownArrow}"
- Echo ∂t"{ResetUpArrow}"
- if !{TopDown}
- Echo -n ∂t;Quote Close -y "{{TempFolder}}Compare_File"
- Echo -n ∂t;Quote Delete -i "{{TempFolder}}Compare_File"
- end
- Echo ∂t"{W1location}"
- Echo -n ∂t;Quote Find __cfSelectionOnEntry__ "{{File1}}"
- Echo -n ∂t;Quote Unmark __cfSelectionOnEntry__ "{{File1}}" ≥dev:null
- If {Close1}
- Echo -n ∂t;Quote Close "{{File1}}"
- End
- Echo ∂t"{W2location}"
- Echo -n ∂t;Quote Find __cfSelectionOnEntry__ "{{File2}}"
- Echo -n ∂t;Quote Unmark __cfSelectionOnEntry__ "{{File2}}" ≥dev:null
- If {Close2}
- Echo -n ∂t;Quote Close "{{File2}}"
- End
- Echo -n ∂t;Quote Open "{ActiveAtStart}"
- If "{TargetAtStart}" ;∂
- Echo -n ∂t;Quote Open -t "{TargetAtStart}"
- End
- Echo End ∂∑ Dev:Null;
- End > "{{TempFolder}}Compare_State"
-
- TileWindows -v -r "{CompareFilesTileRectangle}" "{{File1}}" "{{File2}}"
-
- if !{TopDown}
- Open -t "{{TempFolder}}"Compare_File
- MoveWindow {Left} {Bottom} "{TempFolder}"Compare_File
- SizeWindow {Right} 75 "{TempFolder}"Compare_File
- Find ∞ "{{TempFolder}}"Compare_File
- end
-
- if !{TopDown}
- AddMenu Compare "Find Next Change/ƒ" "CompareFiles•NextChange"
- SetKey Control-DownArrow "CompareFiles•NextChange"
- SetKey Control-UpArrow "CompareFiles•NextChange"
- else
- AddMenu Compare 'Compare Again' 'Compare '"{CompareOptions}"' -selection set "'"{{File1}}"'" "'"{{File2}}"'" && CompareFiles•Quit "The files match"'
- AddMenu Compare "(-0" ""
- AddMenu Compare 'Find Next Change/ƒ' 'Compare '"{CompareOptions}"' -selection next "'"{{File1}}"'" "'"{{File2}}"'" && CompareFiles•Quit "The files match"'
- SetKey Control-DownArrow 'Compare '"{CompareOptions}"' -selection next "'"{{File1}}"'" "'"{{File2}}"'" && CompareFiles•Quit "The files match"'
- SetKey Control-UpArrow 'Compare '"{CompareOptions}"' -selection next "'"{{File1}}"'" "'"{{File2}}"'" && CompareFiles•Quit "The files match"'
- end
- AddMenu Compare "(-1" ""
- AddMenu Compare "Copy Selection »»" "Catenate ∂"{{File1}}∂".§ > ∂"{{File2}}∂".§"
- SetKey Control-RightArrow "Catenate ∂"{{File1}}∂".§ > ∂"{{File2}}∂".§"
- AddMenu Compare "«« Copy Selection" "Catenate ∂"{{File2}}∂".§ > ∂"{{File1}}∂".§"
- SetKey Control-LeftArrow "Catenate ∂"{{File2}}∂".§ > ∂"{{File1}}∂".§"
- AddMenu Compare "(-2" ""
- AddMenu Compare "Done" "CompareFiles•Quit"
-
- if !{TopDown}
- CompareFiles•NextChange
- else
- Compare {CompareOptions} -selection set "{{File1}}" "{{File2}}" && CompareFiles•Quit "The files match"
- end
- end
-
- Exit {CompareStatus}
-